package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.config.WxPayV3Config;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;

    /**
     * 对接微信支付获取小程序拉起微信支付所需的参数
     *
     * @param paymentType 支付方式：订单或者充值
     * @param orderNo     订单编号
     * @return {
     * "timeStamp": "1697186259",
     * "package": "prepay_id=wx131637403639638acce1c384c2354f0000",
     * "paySign": "YoUPakYIrNI+9S4LATn+6MPW55K48vPlf2vJeJInuZsNEGaVgoVYH/SI18Gcj8N8b"
     * }
     */
    @Operation(summary = "对接微信支付获取小程序拉起微信支付所需的参数")
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    @GuiguLogin
    public Result<Map<String, String>> createJsapi(@PathVariable String paymentType, @PathVariable String orderNo) {
        //获取小程序支付参数
        Map<String, String> map = wxPayService.createJsapi(paymentType, orderNo);
        return Result.ok(map);
    }

}
